//
//  MyBespeakVc.swift
//  Venus
//
//  Created by apple on 2018/9/3.
//  Copyright © 2018年 zhaowang. All rights reserved.
// 机构端 - 我的预约详情界面

import UIKit

/// 我的预约详情界面 机构端
class MyBespeakVc: BaseViewController {
    
    /// 显示的控制器
    var showVc : UIViewController = UIViewController()
    
    /// 分段式图
    fileprivate lazy var segVC :UISegmentedControl = {
        let seg = UISegmentedControl.init(items: ["最新预约", "历史预约"])
        seg.tintColor = UIColor.white
        seg.selectedSegmentIndex = 0
        seg.addTarget(self, action: #selector(clickSegVC), for: .valueChanged)
        seg.setTitleTextAttributes(
            [NSAttributedString.Key.foregroundColor : UIColor.init(r: 23, g: 187, b: 254),
             NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)], for: .selected)
        
        seg.setTitleTextAttributes(
            [NSAttributedString.Key.foregroundColor : UIColor.darkGray,
             NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)], for: .normal)
        return seg
    }()
    /// 容纳子控制器的view
    fileprivate lazy var contentView = UIView()
    
    @objc func clickSegVC() {
        
        // 移除其他控制器的view
        showVc.view.removeFromSuperview()
        addShowVc()
    }
    
    // 添加控制器的view
    func addShowVc() {
        showVc = self.children[segVC.selectedSegmentIndex]
        showVc.view.frame = contentView.bounds
        contentView.addSubview(showVc.view)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.bringSubviewToFront(self.navgationBar)
        self.title = "查看预约详情"
        self.view.backgroundColor = UIColor.white
        setupUI()
        self.addChild(LatestBespeakVc())
        self.addChild(HistoryBespeakVc())
        addShowVc()
    }
    
}


extension MyBespeakVc{
    func setupUI(){
        
        view.addSubview(contentView)
        view.addSubview(segVC)
        contentView.backgroundColor = UIColor.black
        segVC.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.top.equalTo(LayoutCommon.navHeight)
            make.height.equalTo(50)
        }
        
        let segVcCenterLine = UIView()
        segVcCenterLine.backgroundColor = UIColor.lightGray
        view.addSubview(segVcCenterLine)
        segVcCenterLine.snp.makeConstraints { (make) in
            make.height.equalTo(51)
            make.top.centerX.equalTo(segVC)
            make.width.equalTo(1)
        }
        
        let lineView = UIView()
        lineView.backgroundColor = nC1
        view.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.top.equalTo(segVC.snp.bottom)
            make.height.equalTo(5)
        }
        
        contentView.snp.makeConstraints { (make) in
            make.top.equalTo(lineView.snp.bottom)
            make.left.right.equalTo(view)
            if #available(iOS 11.0, *) {
                make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            } else {
                make.bottom.equalTo(view.snp.bottom)
            }
        }
        
        
    }
}
